package DuiXiang.src.Computer;

public class Computer {
    private String Brand, color, Resolution;//品牌，颜色，屏幕分辨率
    private boolean format1 = false;//格式化状态，false为未格式化
    private boolean start1 = false;//电脑开机状态，false为未开机
    private boolean os1 = false;//系统安装状态，false为系统未安装
    private Disk[] p = new Disk[0];//盘符数组
    private int count = 0;

    public Computer() {
    }

    public Computer(String brand, String color, String resolution) {
        this.Brand = brand;
        this.color = color;
        this.Resolution = resolution;
    }

    //启动
    public void start() {
        this.setStart1(true);
        System.out.println("开机成功");
    }

    //格式化
    public boolean format(Disk d) {
        for (int i = 0; i < count; i++) {
            if (this.p[i].getName().equals(d.getName())) {
                return false;
            }
        }
        if (count >= p.length) {
            Disk[] px = new Disk[p.length + 1];
            for (int i = 0; i < count; i++)
                px[i] = p[i];
            p = px;
        }
        p[count++] = d;
        this.setFormat1(true);
        return true;
    }

    //安装操作系统
    public boolean os(Software so, String di) {
        if (!os1) {
            if (so.getName().equals("win7") || so.getName().equals("win10") ||
                    so.getName().equals("win11")) {
                if (add(di, so)) {
                    this.setOs1(true);
                    return true;
                }
                return false;
            }
            System.out.println("没有您选择的系统，请重新输入。");
            return false;
        } else
            System.out.println("系统已安装");
        return false;
    }

    //安装一般软件
    public boolean add(String d, Software so) {
        //     if (!start1 && !format1 && !os1) {
        for (int i = 0; i < count; i++) {
            if (p[i].getName().equals(d)) {
                if (so.getMemory() <= this.p[i].getDiskSize()) {
                    p[i].add(so);
                    this.p[i].setDiskSize(this.p[i].getDiskSize() - so.getMemory());
                    return true;
                } else {
                    System.out.println("内存不足");
                    return false;
                }
            }
        }
        System.out.println("没有您选择的盘，请重新输入。");
        return false;
        //      }
    }

    //安装下载软件
    public boolean addSoftware(String d, BitComet so) {
        for (int i = 0; i < count; i++) {
            if (p[i].getName().equals(d)) {
                if (so.getMemory() <= this.p[i].getDiskSize()) {
                    p[i].addBitComet(so);
                    this.p[i].setDiskSize(this.p[i].getDiskSize() - so.getMemory());
                    return true;
                } else {
                    System.out.println("内存不足");
                    return false;
                }
            }
        }
        System.out.println("没有您选择的盘，请重新输入。");
        return false;
        //      }
    }


    //查看盘符情况
    public void showDisk(String d) {
        for (int i = 0; i < count; i++) {
            if (this.p[i].getName().equals(d)) {
                System.out.println("盘符名称 :" + this.p[i].getName() + ",剩余内存：" + this.p[i].getDiskSize() + "M");
                System.out.println("安装软件如下：");
                p[i].showSoftware();
                p[i].showBitComet();
            }
        }
    }

    //下载并安装软件????
    public boolean xiaZai(String na) {
    //    bi.run();
        return false;
    }

    //显示下载软件
    public void showBitComet() {
        for (int i = 0; i < count; i++) {
            p[i].showBitComet();
        }
    }


    //关机
    public void shutDown() {
        this.setStart1(false);
    }

    public String getBrand() {
        return Brand;
    }

    public void setBrand(String brand) {
        Brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getResolution() {
        return Resolution;
    }

    public void setResolution(String resolution) {
        Resolution = resolution;
    }

    public boolean isFormat1() {
        return format1;
    }

    public void setFormat1(boolean format1) {
        this.format1 = format1;
    }

    public boolean isStart1() {
        return start1;
    }

    public void setStart1(boolean start1) {
        this.start1 = start1;
    }

    public boolean isOs1() {
        return os1;
    }

    public void setOs1(boolean os1) {
        this.os1 = os1;
    }
}
